<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(warcorps) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://localhost/log/warcorps/1900-personal-code-library-log-warcorps/log.txt", "r");
$handle = fopen("/root/backup/log/warcorps/log", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);
    $id101 = $arr2["paly"];
    $id102 = $arr2["attribute"];
    $id103 = $arr2["header"];
    $id104 = $arr2["iap"];
    //$id105 = json_encode($id104);

    $id1 = $arr["gamename"];
    $id2 = $arr["createdate"];


    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
        
        $BuyAmmoMoney = $id102[0][BuyAmmoMoney];
        $Character01PlayTotalTime = $id102[0][Character01PlayTotalTime];
        $Character02PlayTotalTime = $id102[0][Character02PlayTotalTime];
        $Character03PlayTotalTime = $id102[0][Character03PlayTotalTime];
        $Character04PlayTotalTime = $id102[0][Character04PlayTotalTime];
        $CurrentCrystal = $id102[0][CurrentCrystal];
        $CurrentMoney = $id102[0][CurrentMoney];
        $Level = $id102[0][Level];
        $UnlockArmor = $id102[0][UnlockArmor];
        $UnlockCharacter01 = $id102[0][UnlockCharacter01];
        $UnlockCharacter02 = $id102[0][UnlockCharacter02];
        $UnlockCharacter03 = $id102[0][UnlockCharacter03];
        $UnlockCharacter04 = $id102[0][UnlockCharacter04];
        $UnlockWeapon = $id102[0][UnlockWeapon];


        $I_Item00 =$id102[0][I_Item00];
        $I_Item01 = $id102[0][I_Item01];
        $I_Item02 = $id102[0][I_Item02];
        $I_Item03 = $id102[0][I_Item03];    
        $I_Item08 = $id102[0][I_Item08];
        $I_Item09 = $id102[0][I_Item09];
        $I_Item10 = $id102[0][I_Item10];
        $I_Item11 = $id102[0][I_Item11];
        $I_Item15 = $id102[0][I_Item15];
        $I_Item16 = $id102[0][I_Item16];


        $gameId = $id103[gameId];
        $gameVersion = $id103[gameVersion];
        $isIAPCrack = $id103[isIAPCrack];
        $isJailbreak = $id103[isJailbreak];
        $timeBegin = $id103[timeBegin];
        $timeEnd = $id103[timeEnd];
        $userId = $id103[userId];


        $paly0_timeEnter = $id101[0][timeEnter];
        $paly0_timeLeave = $id101[0][timeLeave];
        $paly1_timeEnter = $id101[1][timeEnter];
        $paly1_timeLeave = $id101[1][timeLeave];
        $paly2_timeEnter = $id101[2][timeEnter];
        $paly2_timeLeave = $id101[2][timeLeave];
        $paly3_timeEnter = $id101[3][timeEnter];
        $paly3_timeLeave = $id101[3][timeLeave];
        $paly4_timeEnter = $id101[4][timeEnter];
        $paly4_timeLeave = $id101[4][timeLeave];
        $paly5_timeEnter = $id101[5][timeEnter];
        $paly5_timeLeave = $id101[5][timeLeave];
        $paly6_timeEnter = $id101[6][timeEnter];
        $paly6_timeLeave = $id101[6][timeLeave];
        $paly7_timeEnter = $id101[7][timeEnter];
        $paly7_timeLeave = $id101[7][timeLeave];
        $paly8_timeEnter = $id101[8][timeEnter];
        $paly8_timeLeave = $id101[8][timeLeave];
        $paly9_timeEnter = $id101[9][timeEnter];
        $paly9_timeLeave = $id101[9][timeLeave];
        //timeLeave
        $iap_productId_0 = $id104[0][productId];
        $iap_count_0 = $id104[0][count];
        $iap_productId_1 = $id104[1][productId];
        $iap_count_1 = $id104[1][count];
        $iap_productId_2 = $id104[2][productId];
        $iap_count_2 = $id104[2][count];
        $iap_productId_3 = $id104[3][productId];
        $iap_count_3 = $id104[3][count];
        $iap_productId_4 = $id104[4][productId];
        $iap_count_4 = $id104[4][count];
        $iap_productId_5 = $id104[5][productId];
        $iap_count_5 = $id104[5][count];
        $iap_productId_6 = $id104[6][productId];
        $iap_count_6 = $id104[6][count];
        $iap_productId_7 = $id104[7][productId];
        $iap_count_7 = $id104[7][count];
        $iap_productId_8 = $id104[8][productId];
        $iap_count_8 = $id104[8][count];
        $iap_productId_9 = $id104[9][productId];
        $iap_count_9 = $id104[9][count];
        $iap_productId_10 = $id104[10][productId];
        $iap_count_10 = $id104[10][count];
        $iap_productId_11 = $id104[11][productId];
        $iap_count_11 = $id104[11][count];
        $iap_productId_12 = $id104[12][productId];
        $iap_count_12 = $id104[12][count];
        $iap_productId_13 = $id104[13][productId];
        $iap_count_13 = $id104[13][count];
        $iap_productId_14 = $id104[14][productId];
        $iap_count_14 = $id104[14][count];
        $iap_productId_15 = $id104[15][productId];
        $iap_count_15 = $id104[15][count];
        $gamename = $id1;
        $createdate  = $id2;


        mysql_query("INSERT INTO warcorps_query (BuyAmmoMoney,Character01PlayTotalTime,
            Character02PlayTotalTime,
            Character03PlayTotalTime,
            Character04PlayTotalTime,
            CurrentCrystal,
            CurrentMoney,
            Level,
            UnlockArmor,
            UnlockCharacter01,
            UnlockCharacter02,
            UnlockCharacter03,
            UnlockCharacter04,
            UnlockWeapon,
            I_Item00,
            I_Item01,
            I_Item02,
            I_Item03,
            I_Item08,
            I_Item09,
            I_Item10,
            I_Item11,
            I_Item15,
            I_Item16,
            gameId,
            gameVersion,
            isIAPCrack,
            isJailbreak,

            timeBegin,
            timeEnd,
            deviceid,

            paly0_timeEnter,
            paly0_timeLeave,
            paly1_timeEnter,
            paly1_timeLeave,
            paly2_timeEnter,
            paly2_timeLeave,
            paly3_timeEnter,
            paly3_timeLeave,
            paly4_timeEnter,
            paly4_timeLeave,
            paly5_timeEnter,
            paly5_timeLeave,
            paly6_timeEnter,
            paly6_timeLeave,
            paly7_timeEnter,
            paly7_timeLeave,
            paly8_timeEnter,
            paly8_timeLeave,
            paly9_timeEnter,
            paly9_timeLeave,
            iap_productId_0,
            iap_count_0,
            iap_productId_1,
            iap_count_1,
            iap_productId_2,
            iap_count_2,
            iap_productId_3,
            iap_count_3,
            iap_productId_4,
            iap_count_4,
            iap_productId_5,
            iap_count_5,
            iap_productId_6,
            iap_count_6,
            iap_productId_7,
            iap_count_7,
            iap_productId_8,
            iap_count_8,
            iap_productId_9,
            iap_count_9,
            iap_productId_10,
            iap_count_10,
            iap_productId_11,
            iap_count_11,
            iap_productId_12,
            iap_count_12,
            iap_productId_13,
            iap_count_13,
            iap_productId_14,
            iap_count_14,
            iap_productId_15,
            iap_count_15,
            gamename,
            createdate,
            date) 
                    VALUES('$BuyAmmoMoney',
            '$Character01PlayTotalTime',
            '$Character02PlayTotalTime',
            '$Character03PlayTotalTime',
            '$Character04PlayTotalTime',
            '$CurrentCrystal',
            '$CurrentMoney',
            '$Level',
            '$UnlockArmor',
            '$UnlockCharacter01',
            '$UnlockCharacter02',
            '$UnlockCharacter03',
            '$UnlockCharacter04',
            '$UnlockWeapon',
            '$I_Item00',
            '$I_Item01',
            '$I_Item02',
            '$I_Item03',
            '$I_Item08',
            '$I_Item09',
            '$I_Item10',
            '$I_Item11',
            '$I_Item15',
            '$I_Item16',
            '$gameId',
            '$gameVersion',
            '$isIAPCrack',
            '$isJailbreak',
            '$timeBegin',
            '$timeEnd',
            '$userId',
            '$paly0_timeEnter',
            '$paly0_timeLeave',
            '$paly1_timeEnter',
            '$paly1_timeLeave',
            '$paly2_timeEnter',
            '$paly2_timeLeave',
            '$paly3_timeEnter',
            '$paly3_timeLeave',
            '$paly4_timeEnter',
            '$paly4_timeLeave',
            '$paly5_timeEnter',
            '$paly5_timeLeave',
            '$paly6_timeEnter',
            '$paly6_timeLeave',
            '$paly7_timeEnter',
            '$paly7_timeLeave',
            '$paly8_timeEnter',
            '$paly8_timeLeave',
            '$paly9_timeEnter',
            '$paly9_timeLeave',
            '$iap_productId_0',
            '$iap_count_0',
            '$iap_productId_1',
            '$iap_count_1',
            '$iap_productId_2',
            '$iap_count_2',
            '$iap_productId_3',
            '$iap_count_3',
            '$iap_productId_4',
            '$iap_count_4',
            '$iap_productId_5',
            '$iap_count_5',
            '$iap_productId_6',
            '$iap_count_6',
            '$iap_productId_7',
            '$iap_count_7',
            '$iap_productId_8',
            '$iap_count_8',
            '$iap_productId_9',
            '$iap_count_9',
            '$iap_productId_10',
            '$iap_count_10',
            '$iap_productId_11',
            '$iap_count_11',
            '$iap_productId_12',
            '$iap_count_12',
            '$iap_productId_13',
            '$iap_count_13',
            '$iap_productId_14',
            '$iap_count_14',
            '$iap_productId_15',
            '$iap_count_15',
            '$gamename',
            '$createdate',
            '$createdate')") or die(mysql_error());
    }
}
fclose($handle);

print "Import successful!<br>";

?>